package com.heima.stream;
import java.util.*;
import java.util.function.IntBinaryOperator;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamTest {


    public static void main(String[] args) {
        List<Student> studentList = getStudentList();
        Map<String, List<Student>> collect = studentList.stream().collect(Collectors.groupingBy(Student::getSex));
//        Map<String, Double> collect = studentList.stream().filter((student) -> student.getSalary() > 20000).distinct()
//                .sorted(Comparator.comparing(Student::getSalary).reversed())
//                .skip(1)
//                .limit(3)
////                .map(Student::getName)
//                .collect(Collectors.toMap(Student::getName, Student::getSalary));

        System.out.println(collect);

//        System.out.println(Arrays.stream(new int[]{1, 2, 3, 4}).reduce(new IntBinaryOperator() {
//            @Override
//            public int applyAsInt(int left, int right) {
//                return left + right;
//            }
//        }));
//
//        Stream.of(1,2,3,4,5);
    }




    public static List<Student> getStudentList(){
        return Arrays.asList(
                new Student(1,"赵云",28,"男",18888.0),
                new Student(2,"孙尚香",22,"女",23145.0),
                new Student(3,"关羽",31,"男",21321.0),
                new Student(4,"貂蝉",44,"女",9000.0),
                new Student(5,"刘备",51,"男",54000.0),
                new Student(6,"甄姬",25,"女",16888.0),
                new Student(7,"曹操",66,"男",17888.0),
                new Student(8,"小乔",34,"女",28888.0),
                new Student(8,"小乔",34,"女",28888.0)
        );
    }
    static class Student{
        private Integer id;
        private String name;
        private Integer age;
        private String sex;
        private Double salary;

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof Student)) return false;
            Student student = (Student) o;
            return id.equals(student.id) &&
                    name.equals(student.name) &&
                    age.equals(student.age) &&
                    sex.equals(student.sex) &&
                    salary.equals(student.salary);
        }

        @Override
        public int hashCode() {
            return Objects.hash(id, name, age, sex, salary);
        }

        public Student(Integer id, String name, Integer age, String sex, Double salary) {
            this.id = id;
            this.name = name;
            this.age = age;
            this.sex = sex;
            this.salary = salary;
        }
        @Override
        public String toString() {
            return "Student{" +
                    "id=" + id +
                    ", name='" + name + '\'' +
                    ", age=" + age +
                    ", sex='" + sex + '\'' +
                    ", salary=" + salary +
                    '}';
        }
        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        public String getSex() {
            return sex;
        }

        public void setSex(String sex) {
            this.sex = sex;
        }

        public Double getSalary() {
            return salary;
        }

        public void setSalary(Double salary) {
            this.salary = salary;
        }
    }
}
